import json
from .feishu_api import Query_config_data
from .Personal_Information import get_personal_info                 # 导入个人信息获取控模块

# 全局变量声明
number = None                       # 编号
coze_token = None                  # 飞书扣子token
expert_workflow_id = None          # 专家工作流id
adddata_workflow_id = None         # 添加数据工作流id
querydata_workflow_id = None       # 查询数据工作流id
modifydata_workflow_id = None      # 修改数据工作流id
expert_app_token = None            # 专家应用token
log_app_token = None               # 日志应用token
my_name = None                     # 我的小红书名字
my_id = None                       # 我的小红书id
stranger_page = None               # 陌生人消息查询页数
messages_page = None               # 消息查询页数


def initialize_config(access_token,workflow_id,app_token,Scheme_Name,input_number):
    """初始化配置变量，将它们设置为全局变量"""
    global coze_token, expert_workflow_id, adddata_workflow_id, querydata_workflow_id, modifydata_workflow_id, expert_app_token, log_app_token, my_name, my_id, stranger_page, messages_page, number  
    
    # 将input_number赋值给number
    number = input_number
    
    # 查询配置表
    config_data = Query_config_data(access_token, workflow_id, app_token, Scheme_Name)
    fields = json.loads(config_data[0]['fields'])

    # 获取配置表中的数据并设置为全局变量
    
    coze_token = fields['coze_token'][0]['text']
    expert_workflow_id = fields['expert_workflow_id'][0]['text']
    adddata_workflow_id = fields['adddata_workflow_id'][0]['text']
    querydata_workflow_id = fields['querydata_workflow_id'][0]['text']
    modifydata_workflow_id = fields['modifydata_workflow_id'][0]['text']
    expert_app_token = fields['expert_app_token']['link']
    log_app_token = fields['log_app_token']['link']
    stranger_page = fields['stranger_page'][0]['text']
    messages_page = fields['messages_page'][0]['text']


    #调用函数获取个人信息
    my_name, my_id = get_personal_info(coze_token,adddata_workflow_id,log_app_token,number)







